﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using HRSystem.Utility;
using HRSystem.DBAccess;
using HRSystem.Entity;

namespace HRSystem
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            // 注册全局线程异常处理事件侦听
            Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
            new Access().GetDBDateTime();

            //if (!CheckConnection())
            //{
            //    return;
            //}
            PageCommon.Init();
            Application.Run(new FormMDI());
        }

        private static bool CheckConnection()
        {
            if (new Access().IsConnectedDB() == false)
            {
                MessageBox.Show("錯誤：無法連接到數據庫，請聯繫系統管理員！","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                return false;
            }

            return true;
        }

        /// <summary>
        /// 全局线程异常处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        static void Application_ThreadException(object sender,System.Threading.ThreadExceptionEventArgs e)
        {
            FileLog.LogError(e.Exception);
            // 显示全局异常提示            
            MessageBox.Show("錯誤：沒有連接到數據庫或其它系統錯誤，请聯繫系統管理員！","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
        }
    }
}
